package com.example.tcp.server;

import io.netty.buffer.ByteBuf;
import io.netty.buffer.DefaultByteBufHolder;
import io.netty.channel.ChannelHandlerContext;
import lombok.extern.slf4j.Slf4j;

@Slf4j
public abstract class Frame extends DefaultByteBufHolder {

    public Frame(ByteBuf data) {
        super(data);
    }

    public void onRecv(ChannelHandlerContext ctx) {
        Client client = getClient(ctx);
        if(client != null) {
            client.onRecv(this);
        } else {
            log.error("illegal client, close channel: {}", ctx.channel());
            ctx.close();
        }
    }

    public abstract Client getClient(ChannelHandlerContext ctx);
}
